package com.zzyy.study.service.impl;

import com.zzyy.study.service.TongYiService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.ChatClient;
import org.springframework.ai.chat.StreamingChatClient;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.image.ImageClient;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @auther zzyy
 * @create 2024-06-15 23:42
 */
@Service
@Slf4j
public class TongYiSimpleServiceImpl implements TongYiService
{
    /**
     * 自动注入ChatClient、StreamingChatClient，屏蔽模型调用细节
     */
    private final ChatClient chatClient;
    private final StreamingChatClient streamingChatClient;

    @Autowired
    public TongYiSimpleServiceImpl(ChatClient chatClient, StreamingChatClient streamingChatClient) {
        this.chatClient = chatClient;
        this.streamingChatClient = streamingChatClient;
    }

    public String completion(String message) {
        Prompt prompt = new Prompt(new UserMessage(message));
        return chatClient.call(prompt).getResult().getOutput().getContent();
    }

    @Resource
    private ImageClient imageClient;
    @Override
    public ImageResponse genImg(String imgPrompt)
    {
        var prompt = new ImagePrompt(imgPrompt);
        return imageClient.call(prompt);
    }


    @Override
    public String genAudio(String text)
    {
        return null;
    }
}